<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>4761：[Usaco2017 Jan]Cow Navigation</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Usaco2017 Jan]Cow Navigation</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Usaco2017 Jan]Cow Navigation</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                [Usaco2017 Jan]Cow Navigation                </h1>
                <p>时间限制：10s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：128MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><div>Bessie has gotten herself stuck on the wrong side of Farmer John's barn again, and since her vision&nbsp;</div>
<div>is so poor, she needs your help navigating across the barn.The barn is described by an N&times;N grid of&nbsp;</div>
<div>square cells (2&le;N&le;20), some being empty and some containing impassable haybales. Bessie starts in&nbsp;</div>
<div>the lower-left corner (cell 1,1) and wants to move to the upper-right corner (cell N,N). You can gui</div>
<div>de her by telling her a sequence of instructions, each of which is either &quot;forward&quot;, &quot;turn left 90 d</div>
<div>egrees&quot;, or &quot;turn right 90 degrees&quot;. You want to issue the shortest sequence of instructions that wi</div>
<div>ll guide her to her destination. If you instruct Bessie to move off the grid (i.e., into the barn wa</div>
<div>ll) or into a haybale, she will not move and will skip to the next command in your sequence.Unfortun</div>
<div>ately, Bessie doesn't know if she starts out facing up (towards cell 1,2) or right (towards cell 2,1</div>
<div>). You need to give the shortest sequence of directions that will guide her to the goal regardless o</div>
<div>f which case is true. Once she reaches the goal she will ignore further commands.</div>
<div></div>
<div>给定一个N*N的网格(N&lt;=20)，你从左下角出发，要到达右上角，网格中会有障碍物你要给定一个长度最短的行为序</div>
<div>列（往前走，左转，右转），使得无论Bessie处于左下角时是头朝向上还是朝向左都可以在执行完这个序列后到达</div>
<div>右上角如果当前的行为会导致Bessie走到障碍物上或者越界，则Bessie会忽视这个行为</div>
<div></div>
<p></p></p><hr/><h3>输入格式</h3><p><div>The first line of input contains N.</div>
<div>第一行为N表示网格大小</div>
<div>Each of the NN following lines contains a string of exactly N characters, representing the barn. The</div>
<div>&nbsp;first character of the last line is cell 1,1. The last character of the first line is cell N, N.Eac</div>
<div>h character will either be an H to represent a haybale or an E to represent an empty square.</div>
<div></div>
<div>接下来N行每行N列，描述这个网格，H表示障碍物，E表示空地</div>
<div></div>
<div>It is guaranteed that cells 1,1 and N,N will be empty, and furthermore it is guaranteed that there i</div>
<div>s a path of empty squares from cell 1,1 to cell N,N</div>
<div></div>
<div>数据保证左下角和右上角一定是空地，且一定有解</div>
<div></div>
<p></p></p><hr/><h3>输出格式</h3><p><div>On a single line of output, output the length of the shortest sequence of directions that will guide</div>
<div>&nbsp;Bessie to the goal, irrespective whether she starts facing up or right.</div>
<div>输出最短命令序列的长度</div>
<div></div>
<p></p></p><hr/><h3>样例输入</h3><pre>3
EHE
EEE
EEE</pre><hr/><h3>样例输出</h3><pre>9
In this example, the instructions "Forward, Right, Forward, Forward, Left, Forward, Left, Forward, F
orward" will guide Bessie to the destination irrespective of her starting orientation.
当Bessie在左下角的时候，执行前进，右转，前进，前进，左转，前进，左转，前进，前进无论Bessie一开始是朝
向上还是朝向下，都可以到达右上角。</pre><hr/><h3>提示</h3><p><p>&nbsp;<span style="font-family: arial, verdana, helvetica, sans-serif;">1.&ldquo;无论Bessie处于左下角时是头朝向上还是朝向左&rdquo;根据英文原文&ldquo;Bessie doesn't know if she starts out facing up (towards cell 1,2) or right (towards cell 2,1).&rdquo;应为无论Bessie处于左下角时是头朝向上还是朝向右</span><br style="font-family: arial, verdana, helvetica, sans-serif;" />
<span style="font-family: arial, verdana, helvetica, sans-serif;">2.漏了原题很重要的一点:&quot;Once she reaches the goal she will ignore further commands.&quot;即如果Bessie已经到达终点，她会忽视以后的所有行为</span></p></p><hr/><h3>题目来源</h3><p>Gold</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=4761" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=4761" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>